var EXPORTED_SYMBOLS = [ "downloadextender" ];

const { classes: Cc, interfaces: Ci } = Components;

/**
 * downloadextender namespace.
 */
if ("undefined" == typeof(downloadextender)) {
  var downloadextender = {
     //logs message to firefox console
     consoleService : function(consolemessage) {
	 let consoletime = new Date().toLocaleFormat('%H:%M:%S');
	 Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(consoletime+" "+consolemessage);
	 },	 
	 //to get version of Firefox
	 appinfo : function() {return Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);},
	 //compare version of Firefox
	 versioncomparator : function() {return Cc["@mozilla.org/xpcom/version-comparator;1"].getService(Ci.nsIVersionComparator);},	 
	 //returns object nsifile of default downloaddir of firefox
	 downloaddir : function() {return Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager).defaultDownloadsDirectory;},	 
	 //filepicker 
	 fp : function() {return Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);},
	 //nsifile (e.g. can be used to open file by operating system) 
	 nsifile: function() {return Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);},
     //nsilocalfile (extends nsifile) 
	 nsilocalfile: function() {return Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);},
     //filepicker (e.g. selecting a folder or file)
	 filepicker: function() {return Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);},	
	 //can be used to create unique id
     uuidgenerator: function() {return Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);},
	 //download manager of Firefox	 
	 dm: function() {return Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);},
     //webbrowserpersist
	 persist: function() {return Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Ci.nsIWebBrowserPersist);},
     //ioservice, to convert for instance nsifile to file:// format
     ioservice: function() {return Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); },
	 //promptservice (e.g. used to display alert)
     promptservice: function() {return Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService); },	
	 //getting a localised string from specific property file		
     getlocalisedstring : function(propertyfile,string)  {
	 let stringBundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService);
	 let propertyfilefullpath = "chrome://downloadextender/locale/" + propertyfile;
	 let bundle = stringBundleService.createBundle(propertyfilefullpath);
	 let str = bundle.GetStringFromName(string);
	 return str;	 
	 }, 
  };
};

